package com.web.new12306.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.web.new12306.pojo.User;
import com.web.new12306.service.UserService;
import com.web.new12306.service.impl.UserServiceImpl;

/**
 * @author 蔡艳
 * Servlet implementation class updatePersonServlet
 */
@WebServlet("/updatePersonServlet")
public class updatePersonServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		
		UserService userService=new UserServiceImpl();	
		User users=new User();
		
		String id=request.getParameter("id");
		System.out.println(id);
		String username=request.getParameter("username");
		String realname=request.getParameter("realname");
		String sex=request.getParameter("sex");
		String province=request.getParameter("province");
		System.out.print(province);
		String city=request.getParameter("city");
		String cardtype=request.getParameter("cardtype");
		String cardid=request.getParameter("cardid");
		String type=request.getParameter("type");
	
		users.setId(Integer.parseInt(id));
		users.setUsername(username);
		users.setRealname(realname);
		users.setSex(sex);
		users.setProvince(province);
		users.setCity(city);
		users.setCardType(cardtype);
		users.setCardId(cardid);
		users.setType(type);
		
		userService.updatePerson(users);
		
		String msg="修改成功";
        response.setContentType("text/html");
 		out.println("<html>");
 		out.println("<head>");
 		out.println("<title>success</title>");
 		out.println("</head>");
 		out.println("<body>");
 		out.println("<p>" + msg + "</p>");
 		out.println("<p><a href=\"/new12306/frontstage.html\">返回</a></p>");
 		out.println("</body>");
 		out.println("</html>");
 		out.close();
	}

}
